#include "UttpBehaviourTestCase.h"

bool UttpBehaviourTestCase::RunTest(int maxCyclesCount)
{	
	isRunTestDone = false;
	//printf("\nUttpBehaviourTestCase::RunTest() %d %d %d", isTestInitialized, isTestFinished, isTestCleanedUp);

	if(!isTestInitialized)
	{
		isTestInitialized = PrepareBeforeTest();
	}
	else if (isTestInitialized && !isTestFinished)
	{
		isTestFinished = Test();
	} 
	else if(isTestInitialized && isTestFinished && !isTestCleanedUp)
	{
		isTestCleanedUp = CleanUpTest();		
	}
	else if(isTestInitialized && isTestFinished && isTestCleanedUp)
	{	
		//skoncil sa test
		isRunTestDone = true;		
		isTestInitialized = false;
		isTestFinished = false;
		isTestCleanedUp = false;
	}
	
	//podmienka ze cele testovanie konci ak je isRunTestDone == true
	//alebo uplynul pocet cyklov na cely test	
	if (isRunTestDone || cyclesCount >= maxCyclesCount)
	{
		//pozreme sa ako skoncil
		//mala by byt nastavena premenna isTestSuccess
		if (GetIsTestSuccess()) 
		{
			OnTestPassed();
		}
		else 
		{
			OnTestFailed();
		}

		isRunTestDone = true;
	}	
	
	cyclesCount++; //zvys pocet cyklov
	return isRunTestDone;
}

/**
 * hlavna metoda testu, ktora spusta postupne pretazene metody: PrepareForTest, Test, CleanUp
 * tato metoda sa spusta ked sa spusti cas
 */
bool UttpBehaviourTestCase::Test()
{
	printf("UttpBehaviourTestCase::Test()");
	return false;
}

/**
 * metoda ktora by sa mala spustat pred testom, ak treba moze byt prekryta
 */
bool UttpBehaviourTestCase::PrepareBeforeTest()
{
	printf("\nUttpBehaviourTestCase::PrepareBeforeTest()");
	return true;
}
/**
 * metoda ktora by sa mala spustat po teste, ak treba moze byt prekryta
 */
bool UttpBehaviourTestCase::CleanUpTest()
{
	printf("\nUttpBehaviourTestCase::CleanUpTest()");
	return true;
}

/**
 * metoda, ktora by sa mala spustat ak test presiel uspesne
 */
void UttpBehaviourTestCase::OnTestPassed()
{
	printf("\nUttpBehaviourTestCase::OnTestPassed()");
}

/**
 * metoda, ktora by sa mala spustat ak test nepresiel
 */
void UttpBehaviourTestCase::OnTestFailed() 
{
	printf("\nUttpBehaviourTestCase::OnTestFailed()");
}

/**
 * getter pre isTestSuccess
 */
bool UttpBehaviourTestCase::GetIsTestSuccess() 
{
	return isTestSuccess;
}

/**
 * setter pre isTestSuccess
 */
void UttpBehaviourTestCase::SetIsTestSuccess(bool result)
{ 
	isTestSuccess = result;
}
